package com.open.data.component.database

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.open.data.component.dao.WordDao
import com.open.data.component.data.Word


/**************************************************************
 *
 *
 *
 *
 * @author :guangjing.feng.o
 * @createTime: 2021/6/3.
 * @modifyTime:
 * @modifyAuthor:
 * @description:
 *
 ************************************************************/
@Database(entities = [Word::class], version = 1, exportSchema = false)
abstract class WordRoomDatabase : RoomDatabase() {
    abstract fun getWordDao(): WordDao?

    companion object {
        private var INSTANCE: WordRoomDatabase? = null
        fun getInstance(context: Context): WordRoomDatabase? {
            if (INSTANCE == null) {
                synchronized(WordRoomDatabase::class.java) {
                    if (INSTANCE == null) {
                        INSTANCE = Room.databaseBuilder(
                            context.getApplicationContext(),
                            WordRoomDatabase::class.java, "word_database"
                        )
                            .build()
                    }
                }
            }
            return INSTANCE
        }
    }
}